import Control.Monad
import System.IO
import System.Directory
import Data.List
import System.Environment
import Data.List

name1="wanjian"
namearray = ["abcd", "def", "hijk", "lmn"]
namelen = length(namearray)
lostNumbers = [4,8,15,16,23,48] 
{-
main = do
	--putStrLn lostNumbers
	print "lostnumber=", lostNumbers
	line <- getLine
	if null line
		then return ()
		else do
			putStrLn $ reverseWords line
			putStrLn ("len=  " ++ "abcd   " ++ name1)
			--putStrLn ("len=" ++ 10)
			--putStrLn ()
			--let len = length(line)
			--reverseLine=reverseWords line
			--putStrLn reverseLine
			
			--linewords = words line
			--putStrLn  last(linewords)
			main
	putStrLn "end"
-}
--putStrLn "start"


{-
main = do
	colors <- forM [1,2,3,4] (\a -> do
		putStrLn $ "Which color do you associate with the number " ++ show a ++ "?"
		color <- getLine
		return color)
	putStrLn "The colors that you associate with 1, 2, 3 and 4 are: "
	mapM putStrLn colors
-}
{-
main = do
	contents <- getContents
	putStr (shortLinesOnly contents)
	
-}
{-
main = interact shortLinesOnly

shortLinesOnly :: String -> String
shortLinesOnly input =
    let allLines=lines input
        --shortLines = filter (\line -> length line < 10) allLines
        shortLines = filter (\line2 -> length line2 < 10) allLines
        result=unlines shortLines
        
    --let	shortLines = filter (\line -> length line < 10) allLines
    --let	result=unlines shortLines
    --in result
    in result

main = interact respondPalindromes

reverseWords :: String -> String
reverseWords = unwords . map reverse . words
-}
cylinder :: (RealFloat a) => a -> a -> a 
cylinder r h =
    let sideArea = 2 * pi * r * h 
        topArea = pi * r ^2 
    in  sideArea + 2 * topArea 

    {-
respondPalindromes contents = unlines (map (\xs ->
    if isPalindrome xs then "palindrome" else "not a palindrome") (lines contents))
        where isPalindrome xs = xs == reverse xs1
    -}
respondPalindromes :: String -> String    
respondPalindromes = unlines . map (\xs ->
    if isPalindrome xs then "-->palindrome" else "-->not a palindrome") . lines
        where isPalindrome xs = xs == reverse xs
        
{-
number1=12
main = do
    handle <- openFile "todo.txt" ReadMode
    (tempName, tempHandle) <- openTempFile "." "temp"
    contents <- hGetContents handle
    let todoTasks = lines contents
    --numberedTasks = zipWith (\n line -> show n ++ " - " ++ line) [0..] todoTasks
    let numberedTasks = todoTasks
    putStrLn "These are your TO-DO items:"
    putStr $ unlines numberedTasks
    
    putStrLn "Which one do you want to delete?"
    numberString <- getLine
    let number = read numberString
    let numberStr =  todoTasks !! number
    print  number1
    print  number
    putStrLn numberStr
    let newTodoItems = delete numberStr todoTasks
    hPutStr tempHandle $ unlines newTodoItems
    --putStrLn "number=" ++ number
    --putStrLn "number str=" ++ todoTasks !! number
    --netTodoItems = delete (todoTasks !! number) todoTasks
    --newTodoItems = delete (todoTasks !! number) todoTasks 
     {-
   
    -}
    hClose handle
    hClose tempHandle
    
    removeFile "todo.txt"
    renameFile tempName "todo.txt"
    -}

main = do
    args <- getArgs
    progName <- getProgName
    putStrLn "The arguments are:"
    mapM putStrLn args
    putStrLn "The program name is:"
    putStrLn progName    
        
        
        
        
        
        
        
        
        
        
        
